﻿function AzureOnlineQueueDeleteView(context) {

    var self = this;

    var dispatcher = $({});

    var spinner = new SpinnerModel();

    var queue = ko.observable(null);

    function remove() {
        var que = queue();
        var name = que.name();
        var api = context.api();
        spinner.enter();
        api.queues.removeQueue({
            queue: name,
            success: function () {
                spinner.leave();
                context.queues.removeQueue(que);
                dispatcher.trigger('success');
            },
            error: function () {
                spinner.leave();
                return 'notify';
            }
        });
    }

    function addOnSuccess(handler) {
        dispatcher.bind('success', handler);
    };

    function init(que) {
        queue(que);
    }

    function initFromCurrent() {
        var name = context.queues.queue();
        var que = context.queues.findByName(name);
        queue(que);
    }

    self.spinner = spinner;
    self.queue = queue;
    self.init = init;
    self.initFromCurrent = initFromCurrent;
    self.remove = remove;
    self.addOnSuccess = addOnSuccess;
}